package com.fs.cv.service.impl;

import com.fs.cv.dao.TeacherInfoDao;
import com.fs.cv.pojo.pojodao.Course;
import com.fs.cv.pojo.pojodao.Teacher;
import com.fs.cv.pojo.pojodao.User;
import com.fs.cv.pojo.pojoview.StudentInfo;
import com.fs.cv.pojo.pojoview.TeacherInfo;
import com.fs.cv.service.TeacherInfoService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class TeacherInfoServiceImpl implements TeacherInfoService {

    @Autowired
    TeacherInfoDao teacherInfoDao;


    //查询所有的老师信息
    @Override
    public PageInfo<TeacherInfo> queryAllTeacher(Integer userId,Integer currentPage, Integer pageSize) {
        PageHelper.startPage(currentPage,pageSize);
        List<TeacherInfo> teacherInfos = teacherInfoDao.queryAllTeacher(userId);
        PageInfo<TeacherInfo> pageInfo =new PageInfo<>(teacherInfos);
        return pageInfo;
    }

    //通过课程Id查询课程信息
    @Override
    public Course queryCourseInfoByCourseId(Integer courseId) {
        return teacherInfoDao.queryCourseInfoByCourseId(courseId);
    }


    //通过教师ID查询该教师信息
    @Override
    public Teacher queryTeacherInfoByTeacherId(Integer teacherId) {
        return teacherInfoDao.queryTeacherInfoByTeacherId(teacherId);
    }

    //查询剩余未选课程
    @Override
    public List<Course> querySurplusCourse(Integer userId) {
        return teacherInfoDao.querySurplusCourse(userId);
    }

    //修改教师信息
    @Transactional
    @Override
    public Integer editTeacherInfo(Teacher teacher,Integer courseId) {
        int a,b,c;
        if (courseId==teacher.getCourseId()){
            return teacherInfoDao.editTeacherInfo(teacher);
        }else {
            a=teacherInfoDao.editTeacherInfo(teacher);
            b=teacherInfoDao.updateCourseState(teacher.getCourseId(),1);
            c=teacherInfoDao.updateCourseState(courseId,0);
            return a+b+c;
        }
    }

    @Override
    public boolean deleteTeacher(Integer id) {
        return teacherInfoDao.deletedTeacherByTeacherId(id)>0;
    }


  /*  //模糊查询
    @Override
    public List<TeacherInfo> queryPartTeacher(String str) {
        str = "%" + str + "%";
        List<TeacherInfo> list = teacherDao.queryPartTeacher(str);
        return list;*/
}

/*    @Override
    public List queryTeacherByTeacherId(int teacherId) {
        List<String> surplusCourse = teacherDao.querySurplusCourse();
        List<TeacherInfo> teacher = teacherDao.queryTeacherByTeacherId(teacherId);
        ArrayList<Object> result = new ArrayList<>(2);
        result.add(teacher);
        result.add(surplusCourse);
        //arraylist集合前部分为对应的老师信息，后半部分为剩余课程信息
        return result;
    }*/

 /*   @Override
    public void updateTeacher(TeacherInfo teacherView) {

        int teacherId = teacherView.getTeacherId();
        if(isNull(teacherId) == 1 ){
            String courseId = teacherDao.queryIdByCourseName(teacherView.getCourseName());
            teacherView.getCourseName();
            doUpdateTeacher(teacherView);
        }
    }*/



